﻿@model ALinq.BBS.Models.EditTopicModel 
@using System.Diagnostics
@using System.Web.Mvc.Html
@using ALinq.BBS
@using ALinq.BBS.DataAccess
@using ALinq.BBS.App_GlobalResources
@using ALinq.BBS.Common
@{
    Forum forum = ViewBag.Forum;
    Board board = ViewBag.Board;
    var postListIndex = (int)ViewBag.PostListIndex;
    var replyListIndex = (int?)ViewBag.ReplyListIndex;

    var post = Model;
    ;

    if (post != null)
    {
        PageData["Title"] = Label.EditPost;
    }
    else
    {
        PageData["Title"] = Label.AddPost;
    }
    Layout = "_Layout.cshtml";

    PageData["Css"] = "EditPost.css";
    PageData["Scripts"] = new[]{ "/Scripts/syntaxhighlighter/scripts/shCore.js",
                            "/Scripts/syntaxhighlighter/scripts/shBrushCSharp.js",
                            "/Scripts/syntaxhighlighter/scripts/shBrushVb.js"};

    PageData["Styles"] = new[] { "/Scripts/syntaxhighlighter/styles/shCoreDefault.css" };

    Stack<Forum> forums = new Stack<Forum>();
    var p = forum;
    while (p != null)
    {
        forums.Push(p);
        p = p.Parent;
    }

    //string title;
    //string content;
}
<style type="text/css">
    .ke-icon-codeHighLight
    {
        background-image: url(/Scripts/kindeditor/skins/default/code.gif);
        background-position: 0px -2px;
        width: 16px;
        height: 16px;
    }
    .field-validation-error
    {
        width: 372px;
    }
</style>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/kindeditor/kindeditor.js")" type="text/javascript"></script>
<script type="text/javascript">

    KE.lang['codeHighLight'] = "Code High Light";

    KE.plugin['codeHighLight'] = {
        click: function (id) {
            KE.util.selection(id);
            var dialog = new KE.dialog({
                id: id,
                cmd: 'codeHighLight',
                width: 500,
                height: 380,
                title: KE.lang['codeHighLight'],
                yesButton: KE.lang['yes'],
                noButton: KE.lang['no']
            });
            dialog.show();
        },
        check: function (id) {
            return true;
        },
        exec: function (id) {
            KE.util.select(id);
            var iframeDoc = KE.g[id].iframeDoc;
            var dialogDoc = KE.util.getIframeDoc(KE.g[id].dialog);
            if (!this.check(id))
                return false;

            var language = KE.$('selLanguage', dialogDoc).value;
            var code = KE.$('txtCode', dialogDoc).value;
            this.insert(id, language, code);

        },
        insert: function (id, language, code) {

            var html = '<pre class="brush:{0};">{1}</pre><br/>';
            html = html.replace('{0}', language);
            html = html.replace('{1}', code);

            KE.util.insertHtml(id, html);
            KE.layout.hide(id);
            KE.util.focus(id);
        }
    };

    /*
    items: ['source', '|', 'fullscreen', 'undo', 'redo', 'cut', 'copy', 'paste',
    'plainpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
    'justifyfull', 'insertorderedlist', 'insertunorderedlist', '|', 'title', 'fontsize', '|', 'textcolor', 'bold',
    'italic', 'underline', 'strikethrough', 'removeformat', '|', 'image', 'codeHighLight', 'hr', 'link', 'unlink', '|'],
    */
    //codeHighLight
    KE.show({
        id: 'content',
        imageUploadJson: '@ForumSection.Instance.KindEditorDotNetPath/upload_json.ashx',
        fileManagerJson: '@ForumSection.Instance.KindEditorDotNetPath/file_manager_json.ashx',
        allowFileManager: true,
        height: '440px',
        items: [
		'source', '|', 'fullscreen', 'undo', 'redo', 'print', 'cut', 'copy', 'paste',
		'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
		'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
		'superscript', '|', 'selectall', '-',
		'title', 'fontname', 'fontsize', '|', 'textcolor', 'bgcolor', 'bold',
		'italic', 'underline', 'strikethrough', 'removeformat', '|', 'image', 'codeHighLight',
		'flash', 'media', 'advtable', 'hr', 'emoticons', 'link', 'unlink', '|', 'about'
	    ],

        afterCreate: function (id) {
            KE.event.ctrl(document, 13, function () {
                KE.util.setData(id);
                document.forms['mainForum'].submit();
            });
            KE.event.ctrl(KE.g[id].iframeDoc, 13, function () {
                KE.util.setData(id);
                document.forms['mainForum'].submit();
            })
        }
    });
</script>
<div style="margin-bottom: 10px; float: left;">
    @Html.ActionLink("Forum", "Index")
    <span>> </span>
    @foreach (var item in forums)
    {
        @Html.RouteLink(item.Name, RouteNames.PostList, new { boardID = board.ID, forumID = forum.ID });
        <span>> </span>
    }
    <span style="font-size: 12px; font-weight: bold">
        @{Write(post == null ? (replyListIndex == null ? Label.AddPost : "回复帖子") : (replyListIndex == null ? Label.EditPost : "EditReply"));}
    </span>
</div>
<div class="HackBox">
</div>
<div class="spliter" style="background: #ffcf63;">
</div>
@using (Html.BeginForm())
{
    <div style="background-color: #fffbff; font-size: 12px; width: 100%;">
        <div style="margin-top: 6px;">
            <div class="label">
                @Html.LabelFor(o => o.Title)@Label.Colon</div>
            <div style="text-align: left;">
                @*<input name="title" type="text" style="width: 400px" />*@
                @Html.TextBoxFor(o => o.Title, new { style = "width: 400px" })
                <div>@Html.ValidationMessageFor(o => o.Title)</div>
            </div>
        </div>
        <div class="HackBox">
        </div>
        <div>
            <div class="label">
                @Html.LabelFor(o => o.Content)@Label.Colon</div>
            <div style="float: left; text-align: left; width: 86%;">
                @Html.TextAreaFor(o => o.Content, new { id = "content", style = "width: 700px; height: 200px;", visibility = "hidden" })
                <div>@Html.ValidationMessageFor(o => o.Content)</div>
            </div>
            <div class="HackBox">
            </div>
        </div>
        <div class="spliter" style="background-color: #dedfde">
        </div>
        <div class="label">
            &nbsp;</div>
        <div style="text-align: left;">
            <input type="submit" value="发 表" name="btnOK" style="width: 80px" />
        </div>
        <div class="HackBox">
        </div>
    </div>
}
